/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.ubc.icapture.genapha.beans;

import icapture.SQLMgr;
import icapture.beans.DB.DataRequest;
import icapture.beans.DB.DataRequestApproval;
import icapture.beans.DB.User;
import java.util.Calendar;

/**
 *
 * @author btripp
 */
public class DataRequestApprovalDecorator extends DataRequestApproval {

    private DataRequest dataRequest;

    public DataRequestApprovalDecorator(DataRequestApproval dataRequestApproval){
        super(dataRequestApproval);
        dataRequest = SQLMgr.getDataRequest(super.getRequestID());
    }

    /**
     * @return the dataRequest
     */
    public DataRequest getDataRequest() {
        return dataRequest;
    }

    public String getFrom() {
        User user = SQLMgr.getUser(dataRequest.getUserid());
        return user.getFirstName() + " " + user.getLastName();
    }

    /**
     * @return the status
     */
    public String getStatus() {
        if(super.getDateApproved()==null){
            return "Pending";
        }else if(super.isApproved()==true){
            return "Approved";
        }
        return "Denied";
    }

    public void setStatus(String status){
        if(status==null){
            super.setDateApproved(null);
            super.setApproved(false);
        }else{
            if(status.equalsIgnoreCase("Approved")){
                super.setDateApproved(Calendar.getInstance().getTime());
                super.setApproved(true);
            }else if(status.equalsIgnoreCase("Denied")){
                super.setDateApproved(Calendar.getInstance().getTime());
                super.setApproved(false);
            }else{
                super.setDateApproved(null);
                super.setApproved(false);
            }
        }

    }

}
